package com.feng.controller;

import com.feng.annotation.SystemLog;
import com.feng.constants.SystemConstants;
import com.feng.domain.ResponseResult;
import com.feng.domain.dto.AddCommentDto;
import com.feng.domain.entity.Comment;
import com.feng.service.CommentService;
import com.feng.utils.BeanCopyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
@Api(tags = "评论")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @ApiOperation(value = "文章评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId", value = "文章id"),
            @ApiImplicitParam(name = "pageNum", value = "当前页面"),
            @ApiImplicitParam(name = "pageSize", value = "页面数据条数")
    })
    @GetMapping("/commentList")
    public ResponseResult commentList(Long articleId, Integer pageNum, Integer pageSize){
        return commentService.commentList(SystemConstants.ARTICLE_COMMENT, articleId, pageNum, pageSize);
    }

    @ApiOperation(value = "用户评论")
    @PostMapping
    @SystemLog(businessName = "用户评论")
    public ResponseResult comment(@RequestBody AddCommentDto addCommentDto){
        Comment comment = BeanCopyUtil.articleVo(addCommentDto, Comment.class);
        return commentService.commentSave(comment);
    }

    @ApiOperation(value = "优良评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页面"),
            @ApiImplicitParam(name = "pageSize", value = "页面数据条数")
    })
    @GetMapping("/linkCommentList")
    public ResponseResult linkCommentList(Integer pageNum, Integer pageSize){
        return commentService.commentList(SystemConstants.LINK_COMMENT, null, pageNum, pageSize);
    }
}
